class Solution {
    public String longestPalindrome(String s) {
         int len = s.length() ;
         char[] arr = s.toCharArray() ;
         int[][] dp = new int[len][len] ;
         String sum = null ;
         int max = 0 ;  
         for(int i=len-1; i >= 0 ; i --){
            for(int j=i ; j < len ; j ++){
              if(arr[i] == arr[j]){
                  dp[i][j] = i==j?1:(i+1==j?2:(dp[i+1][j-1]!=0?dp[i+1][j-1]+2:0));
              }
              if(dp[i][j]> max){
                max = dp[i][j] ;
                sum = new String(arr , i , max) ;
              }
            }
         }

         return sum ;
    }
}